local rolely_tongbei = fk.CreateSkill {
    name = "rolely_tongbei",
}
rolely_tongbei:addEffect(fk.DamageInflicted, {
    anim_type = "defensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(rolely_tongbei.name)
            and data.from and data.from ~= player
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, { skill_name = rolely_tongbei.name, prompt = "统北：是否发动统北，令手牌上限+1？" })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:addPlayerMark(player, MarkEnum.AddMaxCards, 1)
        room:addPlayerMark(target, MarkEnum.SlashResidue, 1)
        if data.card then
            room:obtainCard(player, data.card, true, fk.ReasonJustMove, player, rolely_tongbei.name)
        end
    end
})

rolely_tongbei:addEffect(fk.DetermineDamageCaused, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(rolely_tongbei.name) and data.to and data.to ~= player and
            data.to:getMark("rolely_tongbei-turn") == 0
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,
            { skill_name = rolely_tongbei.name, prompt = "#rolely_tongbei-asktochose::" .. data.to.id })
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cardtype
        local type = room:askToChoice(player, {
            choices = { "basic", "equip", "trick" },
            skill_name = rolely_tongbei.name,
            prompt = "统北：请选择要声明的类别"
        })
        if type == "basic" then
            cardtype = Card.TypeBasic
        end
        if type == "equip" then
            cardtype = Card.TypeEquip
        end
        if type == "trick" then
            cardtype = Card.TypeTrick
        end
        local chc = { "damage+", "givecard" }
        if #table.filter(data.to:getCardIds("h"), function(id)
                return Fk:getCardById(id).type == cardtype
            end) == 0 then
            table.removeOne(chc, "givecard")
        end
        local chs = room:askToChoice(data.to, {
            choices = chc,
            all_choices = chc,
            skill_name = rolely_tongbei.name,
            prompt = "#rolely_tongbei-choice::" .. player.id,
        })
        if chs == "damage+" then
            data:changeDamage(1)
        else
            if not data.to:isNude() then
                local card = room:askToCards(data.to, {
                    min_num = 1,
                    max_num = 1,
                    include_equip = true,
                    skill_name = rolely_tongbei.name,
                    cancelable = false,
                    pattern = ".|.|.|.|.|" .. type,
                    prompt = "#rolely_tongbei-give:" .. player.id .. "::" .. type,
                })
                if #card > 0 then
                    room:obtainCard(player, card, true, fk.ReasonGive, data.to, rolely_tongbei.name)
                    return
                end
            end
        end
        room:setPlayerMark(data.to, "rolely_tongbei-turn", 1)
    end,
})

Fk:loadTranslationTable {
    ["rolely_tongbei"] = "统北",
    [":rolely_tongbei"] = "当你受到其他角色造成的伤害时，手牌上限+1，使用【杀】的次数+1，若此伤害由牌造成，获得此牌；" ..
        "每回合每名角色限一次，当你对其他角色造成伤害时，你可以令其选择一项：1.交给你一张你声明的牌；2.此伤害+1。",

    ["#rolely_tongbei-asktochose"] = "统北：是否令 %dest 选择交给你牌或额外受到一点伤害？",
    ["#rolely_tongbei-choice"] = "统北：请选择交给 %dest 一张其声明的牌，或额外受到一点伤害。",
    ["#rolely_tongbei-give"] = "统北：交给 %src 一张%arg",

    ["damage+"] = "受到额外伤害",
    ["givecard"] = "交给其一张牌",
}

return rolely_tongbei
